#coding=utf-8
import os, sys
env = Environment()

# 工程名
env["project_name"] = "my_print"
env["project_root"] = '.'

# 指定编译器
env["PREFIX"] = ""
EXEC_PATH = r'/usr/bin'
env["CC"] = env["PREFIX"] + "gcc"
env["AS"] = env["PREFIX"] + "gcc"
env["AR"] = env["PREFIX"] + "ar"
env["CXX"] = env["PREFIX"] + "g++"
env["LINK"] = env["PREFIX"] + "gcc"
env["TARGET_EXT"] = env["PREFIX"] + "elf"
env["SIZE"] = env["PREFIX"] + "size"
env["OBJDUMP"] = env["PREFIX"] + "objdump"
env["OBJCPY"] = env["PREFIX"] + "objcopy"

# 指定编译参数
env.Append(CCFLAGS = ['-std=c99', '-Wall', '-g'])
env.PrependENVPath('PATH', EXEC_PATH)

# 添加头文件路径
env.Append(CPPPATH = ['.'])

# 添加库路径
env["lib_path"] = ["#/build/lib/"]
env.Append(LIBPATH = env["lib_path"])

# 指定链接库
#env["libs"] = ['print'] + ['hello']
env["libs"] = []

# 生成文件位置
env['build_bin_root'] = ['#/build/bin/']
env['build_lib_root'] = ['#/build/lib/']

#Export 和子目录的Import对应，是为了传递env变量
Export('env')

# 执行顶层SConscript
objs = []
objs = Glob("*.c")
objs = objs + Glob("*.cpp")
objs = objs + SConscript("SConscript")

# 构建可执行文件
bin = env.Program(target = env["project_name"], source = objs, LIBS = env["libs"])
env.Install(env["build_bin_root"], bin)
